﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RSPJ.Windows;
using RSPJ.Function;
using RSPJ.Struct;
using System.IO;

namespace RSPJ.Windows
{
    public partial class KTFileType : Form
    {
        private Files file;

        public KTFileType(Files file)
        {
            InitializeComponent();
            this.file = file.Clone();
            this.file.Name = "KT(" + this.file.Name + ")";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            funcKT funcS = new funcKT();   //实例化一个K-T变换类
            if (rbtn1.Checked == true)
            {//如果选择了数据来源为L4，调用L4变换方法
                file = funcS.Landsat4_KT(file);
            }

            if (rbtn2.Checked == true)
            {//如果选择了数据来源为L5，调用L5变换方法
                file = funcS.Landsat5_KT(file);
            }

            if (rbtn3.Checked == true)
            {//如果选择了数据来源为L7,调用L7变换方法
                file = funcS.Landsat7_KT(file);
            }

            file.Head.Bands -= 1;   //K-T变换后只剩六个波段
            file.Head.Data_type = 5;

            using (ConvertData cd = new ConvertData(file))
            {
                if (cd.ShowDialog() == DialogResult.OK)
                {
                    GlobalData.fileList.Add(cd.file);
                    // 打开波段列表
                    if (WindowsStatus.availableBandsList == false)
                    {
                        AvailableBandsList bandsWindow = new AvailableBandsList();
                        WindowsStatus.availableBandsList = true;
                        bandsWindow.Show();
                    }
                    DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }

        private void rbtn1_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtn1.Checked)
            {
                rbtn2.Checked = false;
                rbtn3.Checked = false;
            }
            else if (rbtn2.Checked)
            {
                rbtn1.Checked = false;
                rbtn3.Checked = false;
            }
            else
            {
                rbtn1.Checked = false;
                rbtn2.Checked = false;
            }
        }

        private void rbtn2_CheckedChanged(object sender, EventArgs e)
        {
            rbtn1_CheckedChanged(sender, e);
        }

        private void rbtn3_CheckedChanged(object sender, EventArgs e)
        {
            rbtn1_CheckedChanged(sender, e);
        }
    }
}
